<template>
  <div class="box">
    <div class="card-container">
      <el-row :gutter="10">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
          <el-col :span="20" :offset="0">
            <el-form-item label="名称" prop="name">
              <el-input v-model="queryParams.name" style="width: 215px;" size="small"></el-input>
            </el-form-item>
            <el-form-item label="地址" prop="area">
              <el-cascader clearable filterable style="width: 215px;" v-model="queryParams.area" :options="citylist"
                :props="{
                  expandTrigger: 'click',
                  label: 'name',
                  value: 'code',
                  children: 'child',
                  emitPath: false,
                }"></el-cascader>
            </el-form-item>
            <el-form-item label="类别" prop="category">
              <el-select v-model="queryParams.category" size="small" placeholder="请选择" style="width: 100%">
                <el-option v-for="dict in dict.type.sys_category" :key="dict.value" :label="dict.label"
                  :value="dict.value" />
              </el-select>
            </el-form-item>
            <el-form-item label="级别" prop="level">
              <el-select v-model="queryParams.level" size="small" placeholder="请选择" style="width: 100%">
                <el-option v-for="dict in dict.type.sys_level" :key="dict.value" :label="dict.label"
                  :value="dict.value" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4" :offset="0">
            <el-form-item>
              <el-button  icon="el-icon-search" size="mini" @click="handleQuery">搜索
              </el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
    </div>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button   icon="el-icon-plus" size="mini"   @click="handleAdd"
          v-hasPermi="['refuge:add']">新增</el-button>
          <el-button   icon="el-icon-delete" v-hasPermi="['refuge:remove']" size="mini" :disabled="multiple" v-show="!multiple"
          @click="handleDelete">删除</el-button>
      </el-col>
    </el-row> -->
    <div class="card-container">
      <div class="body-title">
        <div class="body-title-left">避难所</div>
        <div class="body-title-right">
          <el-button icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['refuge:add']">新增</el-button>
          <el-button icon="el-icon-delete" v-hasPermi="['refuge:remove']" size="mini" :disabled="multiple"
            v-show="!multiple" @click="handleDelete">删除</el-button>
        </div>
      </div>
      <!-- v-loading="loading" -->
      <el-table height="450" :data="authenticateList" :row-key="getRowKey"
        @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" :reserve-selection="true" />
        <el-table-column type="index" width="50" label="序号" align="center">
        </el-table-column>
        <el-table-column prop="name" label="名称" align="center">
        </el-table-column>
        <el-table-column prop="category" label="类别" align="center">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_category" :value="scope.row.category" />
          </template>
        </el-table-column>
        <el-table-column prop="acreage" label="面积（平方米）" align="center">
        </el-table-column>
        <el-table-column prop="capacity" label="容纳人数" align="center">
        </el-table-column>
        <el-table-column prop="level" label="级别" align="center">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_level" :value="scope.row.level" />
          </template>
        </el-table-column>
        <el-table-column prop="validArea" label="有效面积（平方米）" align="center">
        </el-table-column>
        <el-table-column prop="addressList" label="所在地址" align="center" width="240">
          <template slot-scope="scope">
            <span>{{ $getAddress(scope.row.addressList, areaList) }}
              {{ scope.row.address }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="160">
          <template slot-scope="scope">
            <el-button type="text" v-hasPermi="['refuge:edit']" size="small"
              @click="handleUpdate(scope.row)">编辑</el-button>
            <el-button @click="handleView(scope.row)" v-hasPermi="['refuge:query']" type="text" size="small">
              查看
            </el-button>
            <!-- <el-button @click="handleDelete(scope.row)" v-hasPermi="['refuge:remove']" type="text" size="small"
              >删除</el-button
            > -->
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>

    <FormDialog ref="formDialog" @searchList="getList" />
  </div>
</template>

<script>
import FormDialog from "./FormDialog.vue";
import mixin from "./mixin.js";
import { listCertificate, delShelter, getAreaJson } from "@/api/earthquakeinfo/shelterManage";
export default {
  name: "certificateAuthorizateReceiving",
  dicts: ["sys_level", "sys_category"],
  mixins: [mixin],
  components: {
    FormDialog,
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      heights: 0,
      // 设备认证管理表格数据
      authenticateList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: "",
        area: "", // 地址
        category: "", // 类别
        level: "", // 级别
      },
      areaList: [], // 省市区JSON
      exportData: [], // 需要导出的数据集合
      multiple: true
    };
  },
  created() {
    this.getList();
  },
  mounted() {
    let temnum = 410;
    this.$nextTick(() => {
      this.heights = window.innerHeight - temnum;
      window.onresize = () => {
        this.heights = window.innerHeight - temnum;
      };
    });
  },
  methods: {
    /** 查询设备认证管理列表 */
    getList() {
      this.loading = true;
      listCertificate(this.queryParams).then(async (response) => {
        let areaData = await getAreaJson();
        this.areaList = areaData.data;
        this.authenticateList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.$refs["queryForm"].resetFields();
      this.handleQuery();
    },
    getRowKey(row) {
      return row.msgId;
    },
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.refugeId);
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.formDialog.handleOpen({ title: "新增", flag: "add" });
    },
    /** 修改按钮操作 */
    handleUpdate(rowdata) {
      this.$refs.formDialog.handleOpen({
        title: "编辑",
        flag: "edit",
        rowdata,
      });
    },
    /** 查看按钮操作 */
    handleView(rowdata) {
      this.$refs.formDialog.handleOpen({
        title: "查看",
        flag: "view",
        rowdata,
      });
    },
    /** 删除按钮操作 */
    handleDelete() {
      const auIds = this.ids;
      this.$modal
        .confirm("是否确认删除当前项？")
        .then(function () {
          return delShelter(auIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
  width: 100%;
  height: 100%;
  padding: 20px;
}

.body-title {
  display: flex;
  position: relative;
  // justify-content: space-between;
  align-items: center;
}

.body-title-left {
  height: 100%;
  font-size: 16px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 600;
  color: #fff;
  line-height: 64px;
}

.body-title-right {
  position: absolute;
  right: 0;
}

::v-deep .box-card .el-card__body {
  padding: 15px 20px 0px 20px;
}

::v-deep .el-dialog__header {
  padding: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid #ebebeb !important;
}
</style>